//
//  HJPasswordTipView.m
//  KaiChat
//
//  Created by lx on 2023/10/17.
//

#import "HJErrorTipView.h"
#import "QMUIButton.h"



@implementation HJErrorTipView

- (instancetype)initWithText:(NSString *)text showCloseButton:(BOOL)showCloseButton {
    if (self = [super initWithFrame:CGRectZero]) {
        
        self.backgroundColor = UIColorMake(0xFFF8F1);
        self.addCornerRadius(10);
        [self clipsToBounds];
        
        UIImageView *iconImageView = [UIImageView addToView:self];
        iconImageView.image = [UIImage imageNamed:@"warn_icon"];
        [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(15);
            make.top.offset(10);
            make.width.height.offset(20);
        }];
        
        UILabel *titleLabel = [UILabel lableWithSuperView:self font:UIFontMake(12) color:UIColor.tj_FF5100Color title:text textAlignment:NSTextAlignmentLeft];
        titleLabel.numberOfLines = 0;
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.inset(10);
            make.left.equalTo(iconImageView.mas_right).offset(10);
            make.right.inset(42);
        }];
        
        [self mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(titleLabel).offset(10);
        }];
        if (showCloseButton) {
            QMUIButton *closeButton = [QMUIButton addToView:self];
            [closeButton setImage:[UIImage imageNamed:@"tipClose"] forState:UIControlStateNormal];
            [closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.inset(10);
                make.right.inset(15);
                make.width.height.offset(16);
            }];
            self -> _closeButton = closeButton;
        } else {
            [titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
                make.right.inset(15);
            }];
        }
    }
    return self;
}
 
@end
